package net.sansi.v3correctserver.config;

import cn.hutool.extra.spring.SpringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sansi.v3correctserver.util.CmmUtil;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.context.request.async.DeferredResult;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * Created by Fang
 * create time : 2023/12/18
 * IDE : IntelliJ IDEA
 */

@Configuration
@EnableOpenApi
//@ConditionalOnProperty(value = "spring.profiles.active", havingValue = "dev")
public class SwaggerConfiguration {

    @Bean
    public Docket createRestApis() {

        return new Docket(DocumentationType.OAS_30)
                //是否启用：注意生产环境需要关闭
                .enable(!CmmUtil.isProdEnv())
                .groupName("net.sansi")
                .genericModelSubstitutes(DeferredResult.class)
                .useDefaultResponseMessages(false)
                .forCodeGeneration(true)
                .ignoredParameterTypes(CookieValue.class)
                .apiInfo(apiInfo())
                .select()
                //以下拦截配置可以三选一，根据需要进行添加
                .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("v3-correct-server")
                .description("亮度矫正服务")
                // 服务条款URL
                //.termsOfServiceUrl("http://localhost:8080/")
                // 作者信息
                //.contact(new Contact("方建超", "", "fangjc1986@qq.com"))
                .version(SpringUtil.getProperty("app.version"))
                .build();
    }
}

